Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
@middy/util
Advanced tools
@middy/util is a utility package that provides a set of helper functions and middlewares to simplify the development of AWS Lambda functions. It is part of the Middy middleware engine, which allows you to compose reusable middleware for your Lambda functions.
createError
The `createError` function helps in creating HTTP errors with a specified status code and message. This is useful for handling errors in a standardized way in your Lambda functions.
const { createError } = require('@middy/util');
const error = createError(400, 'Bad Request');
console.log(error);
jsonSafeParse
The `jsonSafeParse` function safely parses a JSON string into an object. If the string is not valid JSON, it returns `null` instead of throwing an error.
const { jsonSafeParse } = require('@middy/util');
const jsonString = '{"key": "value"}';
const parsedObject = jsonSafeParse(jsonString);
console.log(parsedObject);
normalizeHttpResponse
The `normalizeHttpResponse` function ensures that the HTTP response object conforms to the expected format, making it easier to handle responses in a consistent manner.
const { normalizeHttpResponse } = require('@middy/util');
const response = { statusCode: 200, body: 'Success' };
const normalizedResponse = normalizeHttpResponse(response);
console.log(normalizedResponse);
The `aws-lambda-middleware` package provides a collection of middleware functions for AWS Lambda. It offers similar functionalities to @middy/util, such as error handling and response normalization, but it is not as comprehensive in terms of utility functions.
The `lambda-middleware` package is another alternative that provides middleware for AWS Lambda functions. It focuses on simplifying common tasks like input validation, error handling, and response formatting, similar to @middy/util.
The `lambda-api` package is designed to help build RESTful APIs using AWS Lambda. It includes middleware support and offers functionalities like routing, error handling, and response formatting, making it a good alternative to @middy/util for API development.
Util component of the middy middleware, the stylish Node.js middleware engine for AWS Lambda
To install middy you can use NPM:
npm install --save @middy/util
For documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.
Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.
Licensed under MIT License. Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the Middy team.
FAQs
🛵 The stylish Node.js middleware engine for AWS Lambda (util package)
We found that @middy/util demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.